package mess;

public class LeeCode_03_02 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("abcabcbb"));
    }

    private static int lengthOfLongestSubstring(String s) {
        int[] arr = new int[128];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = -1;
        }
        int len = s.length();
        int start = 0;
        int result = 0;
        for (int i = 0; i < len; i++) {
            int index = s.charAt(i);
            start = Math.max(start, arr[index] + 1);
            result = Math.max(result, i - start + 1);
            arr[index] = i;
        }
        return result;
    }
}
